package com.atguigu.gmall.product.rpc;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseCategoryView;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.model.to.CategoryTo;
import com.atguigu.gmall.product.service.BaseCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author 卡尼奶
 * @Date 2022/5/21 16:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/rpc/inner/product")
public class CategoryRpcController {

    @Autowired
    private BaseCategoryService categoryService;

    /**
     * 获取全部分类以及子分类
     * @return
     */
    @GetMapping("/getAllCategory")
    public Result<List<CategoryTo>> getAllCategory(){
        List<CategoryTo> categoryTos =  categoryService.getAllCategory();
        return Result.ok(categoryTos);
    }


    /**
     * 根据skuId 获取sku的分类信息
     * @param skuId
     * @return
     */
    @GetMapping("/category/view/{skuId}")
    public Result<BaseCategoryView> getSkuCategoryView(@PathVariable("skuId")Long skuId){
        BaseCategoryView baseCategoryView =  categoryService.getSkuCategoryView(skuId);
        return Result.ok(baseCategoryView);
    }

}
